package org.zsk.cs.algorithnm.loadbalance.sendorder;

import com.google.common.collect.Maps;
import org.zsk.cs.algorithnm.entity.EmployTask;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 派单工具类
 * @author zsk
 * 2021/4/19 下午4:37
 */
public class SendOrderUtil {
    private static Map<String, EmployTask> employTaskMap= Maps.newConcurrentMap();


    public static Map<String,EmployTask> getEmployTasksInMap(){
        if (!employTaskMap.isEmpty()){
            return employTaskMap;
        }

        EmployTask employTask01=new EmployTask("001","00",10,10,10,10000);
        EmployTask employTask02=new EmployTask("002","00",20,9,9,10000);
        EmployTask employTask03=new EmployTask("003","00",30,8,8,10000);
        EmployTask employTask04=new EmployTask("004","00",40,7,7,10000);
        EmployTask employTask05=new EmployTask("005","00",50,6,6,10000);
        EmployTask employTask06=new EmployTask("006","00",60,5,5,10000);
        EmployTask employTask07=new EmployTask("007","00",70,4,4,10000);
        EmployTask employTask08=new EmployTask("008","00",80,3,3,10000);
        EmployTask employTask09=new EmployTask("009","00",90,2,2,10000);
        EmployTask employTask10=new EmployTask("010","00",100,1,1,10000);

        employTaskMap.put(employTask01.getEmployNo(),employTask01);
        employTaskMap.put(employTask02.getEmployNo(),employTask02);
        employTaskMap.put(employTask03.getEmployNo(),employTask03);
        employTaskMap.put(employTask04.getEmployNo(),employTask04);
        employTaskMap.put(employTask05.getEmployNo(),employTask05);
        employTaskMap.put(employTask06.getEmployNo(),employTask06);
        employTaskMap.put(employTask07.getEmployNo(),employTask07);
        employTaskMap.put(employTask08.getEmployNo(),employTask08);
        employTaskMap.put(employTask09.getEmployNo(),employTask09);
        employTaskMap.put(employTask10.getEmployNo(),employTask10);

        return employTaskMap;
    }

    public static List<EmployTask> getEmployTasksInList(){
        return new ArrayList<>(getEmployTasksInMap().values());
    }

    public static List<EmployTask> getAvailableEmployTasksInList(){
        return getEmployTasksInMap().values()
                .stream()
                .filter(employTask -> employTask.getStatus().equals("00"))
                .collect(Collectors.toList());
    }

    public static List<String> getTasksForWaitToSend(){
        return Arrays.asList("a00000001","a00000002","a00000003","a00000004","a00000005","a00000006","a00000007","a00000008","a00000009","a00000010",
                "b00000001","b00000002","b00000003","b00000004","b00000005","b00000006","b00000007","b00000008","b00000009","b00000010",
                "c00000001","c00000002","c00000003","c00000004","c00000005","c00000006","c00000007","c00000008","c00000009","c00000010");

    }
}
